console.log('这是video.js')

// 获取canvas
const canvas = document.querySelector('canvas')
const hh = document.querySelector('title')

// 发起ajax询问后端视频流窗口大小
let xhr = new XMLHttpRequest()
xhr.open('get', '/videoSize', false)
xhr.send()
// xhr.onreadystatechange = function() {
//     if (xhr.readyState == 4 && xhr.status == 200) {
//         data = xhr.responseText
//         shape = data.split(' ')
//         canvas.style.width = shape[1]+"px"
//         canvas.style.height = shape[0]+"px"
//         console.log("canvas大小设置成功")
//     }
// }
while (xhr.readyState != 4) {
    ;
}
if (xhr.status == 200) {
    data = xhr.responseText
    shape = data.split(' ')
    canvas.setAttribute('width', shape[1]+"px")
    canvas.setAttribute('height', shape[0]+"px")
    // canvas.style.width = shape[1]+"px"
    // canvas.style.height = shape[0]+"px"
    console.log("canvas大小设置成功", shape)
}
console.log(xhr.readyState);


const c = canvas.getContext("2d")
let flag = 0

setTimeout(
    setInterval(
        function loadimg() {
            let img = new Image()
            img.src = './getImg.jpg'
            img.onload = function () {
                // c.drawImage(img, 0, 0, 300, 150)
                c.drawImage(img, 0, 0)
            }
        },
    20),
0)
// }

